<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>DLC Search Engine: src/main/java/com/utn/searchengine/LocalWordCountManager.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">DLC Search Engine
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/main/java/com/utn/searchengine/LocalWordCountManager.java</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_local_word_count_manager_8java.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * To change this template, choose Tools | Templates</span>
<a name="l00003"></a>00003 <span class="comment"> * and open the template in the editor.</span>
<a name="l00004"></a>00004 <span class="comment"> */</span>
<a name="l00005"></a>00005 <span class="keyword">package </span>com.utn.searchengine;
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keyword">import</span> java.util.ArrayList;
<a name="l00008"></a>00008 <span class="keyword">import</span> java.util.Collection;
<a name="l00009"></a>00009 <span class="keyword">import</span> java.util.Collections;
<a name="l00010"></a>00010 <span class="keyword">import</span> java.util.Comparator;
<a name="l00011"></a>00011 <span class="keyword">import</span> java.util.HashMap;
<a name="l00012"></a>00012 <span class="keyword">import</span> java.util.Iterator;
<a name="l00013"></a>00013 <span class="keyword">import</span> java.util.List;
<a name="l00014"></a>00014 <span class="keyword">import</span> java.util.Map;
<a name="l00015"></a>00015 
<a name="l00022"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html">00022</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html">LocalWordCountManager</a> {
<a name="l00023"></a>00023 
<a name="l00024"></a>00024     <span class="keyword">private</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html">Vocabulary</a> vocabulary;
<a name="l00025"></a>00025     <span class="keyword">private</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html">PostList</a> postList;
<a name="l00026"></a>00026     <span class="keyword">private</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_manager.html">DocumentManager</a> documentManager;
<a name="l00027"></a>00027     <span class="keyword">private</span> Map&lt;String, Double&gt; weigthQuery;
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#ae7395f3b7b0700967981f31647d97f29">00029</a>     <span class="keyword">public</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#ae7395f3b7b0700967981f31647d97f29">LocalWordCountManager</a>() {
<a name="l00030"></a>00030         vocabulary = <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html">Vocabulary</a>();
<a name="l00031"></a>00031         postList = <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html">PostList</a>();
<a name="l00032"></a>00032         documentManager = <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_manager.html">DocumentManager</a>();
<a name="l00033"></a>00033         weigthQuery = <span class="keyword">new</span> HashMap&lt;String, Double&gt;();
<a name="l00034"></a>00034         vocabulary.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html#abb139c8ea23882bd849a5e4fc7efecc3">loadVocabularyWords</a>();
<a name="l00035"></a>00035     }
<a name="l00036"></a>00036 
<a name="l00041"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a7fdb486e1b5ae7581eb27fa139432d61">00041</a>     <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a7fdb486e1b5ae7581eb27fa139432d61">addDocument</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00042"></a>00042         Map&lt;String, Integer&gt; pages = <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html">WordCount</a>.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html#a6844e58166eaeaf8830e9333b6e54d3d">retrieveWordCount</a>(document);
<a name="l00043"></a>00043         vocabulary.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html#ab1368538cfbf3263aa0c4a0b7b244b6e">addDocumentWords</a>(pages);
<a name="l00044"></a>00044         documentManager.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_manager.html#a8295975e2a38a2efbd526921af105b79">addDocument</a>(document);
<a name="l00045"></a>00045         postList.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html#af23ef7a6ccf86e12327af6c2b0f1e099">addDocumentWords</a>(pages, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00046"></a>00046     }
<a name="l00047"></a>00047 
<a name="l00052"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a4baf4121a603c1471bcc9e0856844bae">00052</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a4baf4121a603c1471bcc9e0856844bae">getTotalNumberOfDocuments</a>() {
<a name="l00053"></a>00053         <span class="keywordflow">return</span> documentManager.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_manager.html#a416e11c09839b8f261bdb3e6b1036c89">documentsSize</a>();
<a name="l00054"></a>00054     }
<a name="l00055"></a>00055 
<a name="l00062"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acde1570f752717dfe74eb14e8ad682c7">00062</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acde1570f752717dfe74eb14e8ad682c7">timesThatAWordRepeatsOnDocument</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00063"></a>00063         <span class="keywordflow">return</span> postList.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html#a8f3297b7f1318ebb41af197f7b516cd8">totalTimesThatWordRepeatsOnDocument</a>(word, document);
<a name="l00064"></a>00064     }
<a name="l00065"></a>00065 
<a name="l00071"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#aad7261a1c223513a9126656550fd7d12">00071</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#aad7261a1c223513a9126656550fd7d12">numberOfDocumentsWhereWordAppears</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word) {
<a name="l00072"></a>00072         <span class="keywordflow">return</span> postList.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html#a1c1f62c62dd582404f6010a568a47daa">numberOfDocumentsWhereWordAppears</a>(word);
<a name="l00073"></a>00073     }
<a name="l00074"></a>00074 
<a name="l00081"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acd1c0280284cab09e9c1aca3686d9545">00081</a>     <span class="keyword">public</span> <span class="keywordtype">double</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acd1c0280284cab09e9c1aca3686d9545">inverseFrecuency</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word) {
<a name="l00082"></a>00082         <span class="keywordflow">if</span> (word == null) {
<a name="l00083"></a>00083             <span class="keywordflow">return</span> 0;
<a name="l00084"></a>00084         }
<a name="l00085"></a>00085         <span class="keywordtype">double</span> N = <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a4baf4121a603c1471bcc9e0856844bae">getTotalNumberOfDocuments</a>();
<a name="l00086"></a>00086         <span class="keywordtype">double</span> nr = word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a26c2057e690a42fe2488b70ce6809ee8">getNr</a>();
<a name="l00087"></a>00087         <span class="keywordflow">if</span> (nr == 0) {
<a name="l00088"></a>00088             <span class="keywordflow">return</span> 0;
<a name="l00089"></a>00089         }
<a name="l00090"></a>00090         <span class="keywordtype">double</span> cociente = N / nr;
<a name="l00091"></a>00091         <span class="keywordtype">double</span> result = Math.log10(cociente);
<a name="l00092"></a>00092         <span class="keywordflow">return</span> result;
<a name="l00093"></a>00093     }
<a name="l00094"></a>00094 
<a name="l00104"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a46f22d947651c786498ae8f93a7ccb61">00104</a>     <span class="keyword">public</span> <span class="keywordtype">double</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a46f22d947651c786498ae8f93a7ccb61">getDocumentModule</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document, <span class="keywordtype">double</span> invFrecuency){
<a name="l00105"></a>00105        <span class="keywordflow">if</span>(document ==null){
<a name="l00106"></a>00106            <span class="keywordflow">return</span> 0;
<a name="l00107"></a>00107        }
<a name="l00108"></a>00108        <span class="keywordflow">if</span>(invFrecuency ==0){
<a name="l00109"></a>00109            <span class="keywordflow">return</span> 0;
<a name="l00110"></a>00110        }   
<a name="l00111"></a>00111         List&lt;Word&gt; words = postList.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html#a64dbfffa646daea156a31746bb0685e9">getWordsDocument</a>(document);
<a name="l00112"></a>00112        <span class="keywordtype">double</span> moduleResult =0;
<a name="l00113"></a>00113         <span class="keywordflow">for</span>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word: words){
<a name="l00114"></a>00114             <span class="keywordtype">double</span> termFrecuencyOnDocument = word.getFrecuency();
<a name="l00115"></a>00115             <span class="keywordtype">double</span> product = termFrecuencyOnDocument * invFrecuency;
<a name="l00116"></a>00116             <span class="keywordtype">double</span> potency = Math.pow(product, 2);
<a name="l00117"></a>00117             moduleResult += potency;
<a name="l00118"></a>00118         }
<a name="l00119"></a>00119         moduleResult = Math.pow(moduleResult, 0.5);
<a name="l00120"></a>00120         <span class="keywordflow">return</span> moduleResult;
<a name="l00121"></a>00121     }
<a name="l00122"></a>00122 
<a name="l00131"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a6e756855cacf68cbc81edd8ee6876461">00131</a>     <span class="keyword">public</span> <span class="keywordtype">double</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a6e756855cacf68cbc81edd8ee6876461">estimateWeight</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00132"></a>00132        <span class="keywordflow">if</span>(document ==null){
<a name="l00133"></a>00133            <span class="keywordflow">return</span> 0;
<a name="l00134"></a>00134        }
<a name="l00135"></a>00135        <span class="keywordflow">if</span>(word ==null){
<a name="l00136"></a>00136            <span class="keywordflow">return</span> 0;
<a name="l00137"></a>00137        }
<a name="l00138"></a>00138         <span class="keywordtype">double</span> tfri;
<a name="l00139"></a>00139         <span class="keywordflow">if</span> (document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>().equalsIgnoreCase(<span class="stringliteral">&quot;query&quot;</span>)) {
<a name="l00140"></a>00140             tfri = <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html">WordCount</a>.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html#a460ac30e0a831c1119ba047c91da0a15">getTF</a>(word, document);
<a name="l00141"></a>00141         } <span class="keywordflow">else</span> {
<a name="l00142"></a>00142             <span class="keywordtype">int</span> nr = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acde1570f752717dfe74eb14e8ad682c7">timesThatAWordRepeatsOnDocument</a>(word, document);
<a name="l00143"></a>00143             <span class="keywordflow">if</span> (nr == 0) {
<a name="l00144"></a>00144                 <span class="keywordflow">return</span> 0;
<a name="l00145"></a>00145             }
<a name="l00146"></a>00146             tfri = nr;
<a name="l00147"></a>00147         }
<a name="l00148"></a>00148         <span class="keywordtype">double</span> invFrec = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acd1c0280284cab09e9c1aca3686d9545">inverseFrecuency</a>(word);
<a name="l00149"></a>00149         <span class="keywordtype">double</span> numerator = tfri * invFrec;
<a name="l00150"></a>00150         <span class="keywordtype">double</span> denominator;
<a name="l00151"></a>00151         <span class="keywordflow">if</span> (document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a2b03754624147f5f1a9ea50c549e9606">getModule</a>() != -1) {
<a name="l00152"></a>00152             denominator = document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a2b03754624147f5f1a9ea50c549e9606">getModule</a>();
<a name="l00153"></a>00153         } <span class="keywordflow">else</span> {
<a name="l00154"></a>00154             document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#ad8a50ff977b6138ae86a199a1f987459">setModule</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a46f22d947651c786498ae8f93a7ccb61">getDocumentModule</a>(document, invFrec));
<a name="l00155"></a>00155             documentManager.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_manager.html#a482dbc878f08c89dc82d8b17d4ba689f">setDocumentModule</a>(document);
<a name="l00156"></a>00156             denominator = document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a2b03754624147f5f1a9ea50c549e9606">getModule</a>();
<a name="l00157"></a>00157         }
<a name="l00158"></a>00158         <span class="keywordflow">return</span> numerator / denominator;
<a name="l00159"></a>00159     }
<a name="l00160"></a>00160 
<a name="l00168"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#adbea00f02f037e78ff02a412d876ea5c">00168</a>     <span class="keyword">public</span> Collection&lt;Similitude&gt; <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#adbea00f02f037e78ff02a412d876ea5c">determinateBestSimilitude</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) 
<a name="l00169"></a>00169     {
<a name="l00170"></a>00170         <span class="keywordflow">if</span>(document ==null){
<a name="l00171"></a>00171            <span class="keywordflow">return</span> null;
<a name="l00172"></a>00172        }
<a name="l00173"></a>00173         Map &lt;String, Integer&gt; wordsOfQuery = <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html">WordCount</a>.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word_count.html#a6844e58166eaeaf8830e9333b6e54d3d">retrieveWordCount</a>(document);
<a name="l00174"></a>00174         wordsOfQuery = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9fc1b920828649066ae8151be2ba06dd">filterQuery</a>(wordsOfQuery);
<a name="l00175"></a>00175         Collection&lt;String&gt; c = wordsOfQuery.keySet();
<a name="l00176"></a>00176         document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#ad8a50ff977b6138ae86a199a1f987459">setModule</a>(this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#adb499e31d2d177c13d7c30fc95d09984">getQueryModule</a>(wordsOfQuery));
<a name="l00177"></a>00177         ArrayList&lt;Similitude&gt; sumilitudes = <span class="keyword">new</span> ArrayList&lt;Similitude&gt;();
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         Collection &lt;DocumentResults&gt; documentResults = postList.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_post_list.html#a33bdf8f8460ac8622d069786707051f0">getCandidateDocumentsFiltered</a>(c);
<a name="l00180"></a>00180         <span class="keywordflow">if</span>(documentResults.isEmpty()){
<a name="l00181"></a>00181            <span class="keywordflow">return</span> null;
<a name="l00182"></a>00182         }
<a name="l00183"></a>00183         <span class="keywordflow">for</span>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_results.html">DocumentResults</a> res: documentResults){
<a name="l00184"></a>00184             sumilitudes.add(this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9cc53ea7ff20a437016f205f5c174335">determinateSimilitude</a>(wordsOfQuery, res.getDocument(), document));
<a name="l00185"></a>00185         }
<a name="l00186"></a>00186         sortSimilitude(sumilitudes);
<a name="l00187"></a>00187         <span class="keywordflow">return</span> sumilitudes;
<a name="l00188"></a>00188 
<a name="l00189"></a>00189     }
<a name="l00190"></a>00190 
<a name="l00195"></a>00195     <span class="keyword">private</span> <span class="keywordtype">void</span> sortSimilitude (  List&lt;Similitude&gt; sumilitu){
<a name="l00196"></a>00196         Comparator&lt;Similitude&gt; comparator = <span class="keyword">new</span> Compare () ;
<a name="l00197"></a>00197         Collections.sort(sumilitu,  comparator);
<a name="l00198"></a>00198     }
<a name="l00199"></a>00199 
<a name="l00203"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager_1_1_compare.html">00203</a>     <span class="keyword">class </span><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager_1_1_compare.html">Compare</a> <span class="keyword">implements</span> Comparator&lt;Similitude&gt; {
<a name="l00204"></a>00204 
<a name="l00205"></a>00205         @Override
<a name="l00206"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager_1_1_compare.html#a90f1399631f8dc62527a71d36cf40b3e">00206</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager_1_1_compare.html#a90f1399631f8dc62527a71d36cf40b3e">compare</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html">Similitude</a> lhs, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html">Similitude</a> rhs) {
<a name="l00207"></a>00207             <span class="keywordflow">if</span> (rhs.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html#af4c995a7282bbd1dde1c0f5e076e8c78">getSimilitude</a>() &gt;= lhs.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html#af4c995a7282bbd1dde1c0f5e076e8c78">getSimilitude</a>()) {
<a name="l00208"></a>00208                 <span class="keywordflow">return</span> 1;
<a name="l00209"></a>00209             } <span class="keywordflow">else</span> {
<a name="l00210"></a>00210                 <span class="keywordflow">return</span> -1;
<a name="l00211"></a>00211             }
<a name="l00212"></a>00212         }
<a name="l00213"></a>00213     }
<a name="l00214"></a>00214 
<a name="l00222"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#adb499e31d2d177c13d7c30fc95d09984">00222</a>     <span class="keyword">public</span> <span class="keywordtype">double</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#adb499e31d2d177c13d7c30fc95d09984">getQueryModule</a>(Map&lt;String, Integer&gt; wordsOfQuery) {
<a name="l00223"></a>00223         <span class="keywordtype">double</span> moduleResult = 0;
<a name="l00224"></a>00224         Iterator iterator = wordsOfQuery.entrySet().iterator();
<a name="l00225"></a>00225         <span class="keywordflow">while</span> (iterator.hasNext()) {
<a name="l00226"></a>00226             Map.Entry entry = (Map.Entry) iterator.next();
<a name="l00227"></a>00227             <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word = this.vocabulary.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html#a34b2ee9baca77f11c23cf3b07649ca6b">getVocabularyWords</a>().get(entry.getKey().toString());
<a name="l00228"></a>00228             <span class="keywordtype">double</span> termFrecuencyOnDocument = (Integer) entry.getValue();
<a name="l00229"></a>00229             <span class="keywordtype">double</span> invFrecuency = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#acd1c0280284cab09e9c1aca3686d9545">inverseFrecuency</a>(word);
<a name="l00230"></a>00230             <span class="keywordtype">double</span> product = termFrecuencyOnDocument * invFrecuency;
<a name="l00231"></a>00231             <span class="keywordtype">double</span> potency = Math.pow(product, 2);
<a name="l00232"></a>00232             moduleResult += potency;
<a name="l00233"></a>00233         }
<a name="l00234"></a>00234         moduleResult = Math.pow(moduleResult, 0.5);
<a name="l00235"></a>00235         <span class="keywordflow">return</span> moduleResult;
<a name="l00236"></a>00236     }
<a name="l00237"></a>00237 
<a name="l00245"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9cc53ea7ff20a437016f205f5c174335">00245</a>     <span class="keyword">public</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html">Similitude</a> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9cc53ea7ff20a437016f205f5c174335">determinateSimilitude</a>(Map&lt;String, Integer&gt; wordsOfQuery, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document1, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document2) {
<a name="l00246"></a>00246         <span class="keywordtype">double</span> coseno = 0;
<a name="l00247"></a>00247         <span class="keywordtype">double</span> weight2;
<a name="l00248"></a>00248         Iterator iterator = wordsOfQuery.entrySet().iterator();
<a name="l00249"></a>00249         <span class="keywordflow">while</span> (iterator.hasNext()) {
<a name="l00250"></a>00250             Map.Entry entry = (Map.Entry) iterator.next();
<a name="l00251"></a>00251             <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word = this.vocabulary.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html#a34b2ee9baca77f11c23cf3b07649ca6b">getVocabularyWords</a>().get(entry.getKey().toString());
<a name="l00252"></a>00252             <span class="keywordtype">double</span> weight1 = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a6e756855cacf68cbc81edd8ee6876461">estimateWeight</a>(word, document1);
<a name="l00253"></a>00253             <span class="keywordflow">if</span> (!weigthQuery.containsKey(word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>())) {
<a name="l00254"></a>00254                 weight2 = this.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a6e756855cacf68cbc81edd8ee6876461">estimateWeight</a>(word, document2);
<a name="l00255"></a>00255                 weigthQuery.put(word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>(), weight2);
<a name="l00256"></a>00256             } <span class="keywordflow">else</span> {
<a name="l00257"></a>00257                 weight2 = weigthQuery.get(word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00258"></a>00258             }
<a name="l00259"></a>00259 
<a name="l00260"></a>00260             coseno += weight1 * weight2;
<a name="l00261"></a>00261 
<a name="l00262"></a>00262         }
<a name="l00263"></a>00263         <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_similitude.html">Similitude</a>(document1, document2, coseno);
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265 
<a name="l00271"></a><a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9fc1b920828649066ae8151be2ba06dd">00271</a>     <span class="keyword">public</span> Map&lt;String, Integer&gt; <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_local_word_count_manager.html#a9fc1b920828649066ae8151be2ba06dd">filterQuery</a>(Map&lt;String, Integer&gt; wordsOfQuery) {
<a name="l00272"></a>00272         Map&lt;String, Integer&gt; filteredQuery = <span class="keyword">new</span> HashMap&lt;String, Integer&gt;();
<a name="l00273"></a>00273         Iterator iterator = wordsOfQuery.entrySet().iterator();
<a name="l00274"></a>00274         <span class="keywordflow">while</span> (iterator.hasNext()) {
<a name="l00275"></a>00275             Map.Entry entry = (Map.Entry) iterator.next();
<a name="l00276"></a>00276             <span class="keywordflow">if</span> (vocabulary.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_vocabulary.html#a987cf76169508e0c080e815218b4a2a5">containsWord</a>(entry.getKey().toString())) {
<a name="l00277"></a>00277                 filteredQuery.put(entry.getKey().toString(), (Integer) entry.getValue());
<a name="l00278"></a>00278             }
<a name="l00279"></a>00279         }
<a name="l00280"></a>00280         <span class="keywordflow">return</span> filteredQuery;
<a name="l00281"></a>00281     }
<a name="l00282"></a>00282 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Feb 16 2012 02:45:40 for DLC Search Engine by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
